package com.q.springboot.framework.util;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;
import java.util.function.Supplier;

/**
 * @author qmf
 * @date 2022年01月24日 10:13
 * @description
 */
@Component
public class FuncTest {

    @Resource
    private RedisUtil redisUtil;

    public <T> T getOneById(String id, RedisSupplier<T> redisSupplier) {
        Object value = redisUtil.get(id);
        if (Objects.isNull(value)) {
            T result = redisSupplier.get();
            redisUtil.set(id, result);
            return result;
        }
        return (T) value;
    }
}
